package com.bestvike.stone.core.util.area;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import lombok.ToString;

import java.util.Collection;


/**
 * 县级行政区
 * Created by 许崇雷 on 2018-07-28.
 */
@Data
@EqualsAndHashCode(exclude = {"townCollection", "city"})
@ToString(exclude = {"townCollection", "city"})
public final class County implements IArea {
    @JSONField(ordinal = 1)
    private final String code;
    @JSONField(ordinal = 2)
    private final String name;
    @JSONField(ordinal = 3)
    private final Collection<Town> townCollection = new TownCollection(this);
    @Setter(AccessLevel.PACKAGE)
    @JSONField(serialize = false, deserialize = false)
    private transient City city;

    public County(String code, String name, Collection<Town> townCollection) {
        this.code = code;
        this.name = name;
        if (townCollection != null)
            this.townCollection.addAll(townCollection);
    }

    public TownCollection getTownCollection() {
        return (TownCollection) this.townCollection;
    }
}
